package com.zlm.weather.util;

import javax.xml.bind.annotation.XmlRootElement;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.util.Map;

/**
 * @Author: 郑
 * @Date: Create in 2020-1-17.
 */
public class AnnotationUtil {

    public static void updateParam(String className,String value) throws Exception {
        Class<?> aClass = Class.forName(className);
        XmlRootElement annotation = aClass.getAnnotation(XmlRootElement.class);
        //获取注解代理实例
        InvocationHandler invocationHandler = Proxy.getInvocationHandler(annotation);
        //获取指定字段
        Field memberValues = invocationHandler.getClass().getDeclaredField("memberValues");
        //打开权限
        memberValues.setAccessible(true);
        Map<String,Object> map = (Map<String, Object>) memberValues.get(invocationHandler);
        //修改值
        map.put("name",value);

    }

}
